package com.jwm.power.repository;

import com.jwm.power.model.entity.Depts;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;
public interface DeptsRepository extends JpaRepository<Depts, Integer>, JpaSpecificationExecutor<Depts> {
    //  获取最大编码
    @Query(value = "select top 1 RIGHT(DeptCode,2) from Depts where ParentCode=?1 order by DeptCode DESC ", nativeQuery = true)
    String getMaxCode(String parentCode);
    List<Depts> findByDeptnameAndDeptidNot(@Param("deptname") String deptName, @Param("deptid") Integer deptId );
    //  获取最大序号
    @Query(value = "select top 1 sn from Depts where ParentCode=?1 order by sn DESC ", nativeQuery = true)
    Integer getMaxSn(String parentCode);
    Depts findByDeptcode(@Param("deptcode") String deptcode);
}
